<?php
if (!defined('INEZCMS')) {
	exit ('Access Denied');
}

if (isset ($_POST['username']) && $_POST['username'] != '' && isset($_POST['sub'])) {
	    
        if($_POST["token"]<>$_SESSION["WSTOKEN_NAME"]){
           exit;
	   }
       $_SESSION["WSTOKEN_NAME"]="";
           
		unset ($_POST['sub']);
		$captcha = trim($_POST['captcha']);
		$from = trim($_POST['from']);
		$username = trim($_POST['username']);
		$password = trim($_POST['password']);
		
		$email = trim($_POST['email']);
		$ip = get_client_ip();

		$company = trim($_POST['company']);
		$contect = trim($_POST['contect']);
		$mobile = trim($_POST['mobile']);

		if (limit_ip('user_limit_ip', $ip)) {
			jump(-1, 54); //禁用IP
		}
		$shield_arr = ez_get_cache('no_words'); //屏蔽词语

		$username_pass = reg_name($username, 3, 15, $shield_arr);
		if ($username_pass == -1) {
			jump(-1, 1); //用户名不合法
		}
		elseif ($username_pass == -2) {
			jump(-1, 2); //包含非法词汇
		}
		elseif ($ezhand->check_user($username) == 'false') {
			jump(-1, 6); //用户名已存在
		}

		$password_pass = reg_password($password);
		if ($password_pass == 0) {
			jump(-1, 3); //密码位数错误
		}

		$email_pass = reg_email($email);
		if ($email_pass == 0) {
			jump(-1, 7); //邮箱格式错误
		}
		elseif ($ezhand->check_email($email) == 'false') {
			jump(-1, 8); //邮箱已存在
		}
        if($captcha<>$_SESSION["captcha"]){
            
            jump(-1, 5); 
        }
        $_SESSION["captcha"]="";
         unset($_SESSION["captcha"]);
	    srand(seed());
        $encrypt=mt_rand (100000,999999);
    
			include EZROOT . '/comm/uc_define.php';
			include_once EZROOT . '/uc_client/client.php';
			//$uc_name = iconv("utf-8", "utf-8", $username);
            
            
			$ucid = uc_user_register($username, $password, $email);
        
        
			if ($ucid == -1) {
				jump(-1, 1); //用户名不合法
			}
			elseif ($ucid == -2) {
				jump(-1, 2); //包含非法词汇
			}
			elseif ($ucid == -3) {
				jump(-1, 6); //用户名已存在
			}
			elseif ($ucid == -4) {
				jump(-1, 7); //邮箱格式错误
			}
			elseif ($ucid == -5) {
				jump(-1, 7); //邮箱格式错误
			}
			elseif ($ucid == -6) {
				jump(-1, 8); //邮箱已存在
			}
			elseif ($ucid <= 0) {
				jump(-1, 999); //邮箱已存在
			}
       
		$info['regdate'] = time();
		$info['regip'] = $ip;
		$info['lastdate'] = time();
		$info['loginnum'] = 1;
        $info['encrypt']=$encrypt;
        $md5pwd = md5($password);
         
		$info['point'] = (int) $webset['reg_jifen'];
		$info['groupid'] =1;
		$info['password'] = $md5pwd;
		$info['username'] = $username;
		$info['mobile'] = $mobile;
        $info['email'] = $email;
        
        $info['company'] = $company;
        $info['contect'] = $contect;
		$info['ucid'] = $ucid;

		if ($webset['islock'] == 1) { 
			$info['islock'] = 1;
		} else {
			$info['islock'] = 0;
		}

		$uid = $ezhand->insert('member', $info, 0); //插入会员
		if ($uid <= 0) {
			exit (mysql_error() . '插入会员失败');
		}

		$tg = $webset['tgbl'];
		unset ($data);
		$data['uid'] = $uid;
		$data['username'] = $username;
		$data['tg'] = $tg;
		$data['webnick'] = WEBNICK;
		$data['email'] = $email;
		$msg_zhuce = $ezhand->msg_insert($data, 1); //1号站内信

		if ($webset['reg_jifen'] > 0) { //注册送大于0时，发送明细
			unset ($info);
			$info['uid'] = $uid;
			$info['shijian'] = 1;
			$info['jifen'] = (int) $webset['reg_jifen'];
			$mingxi_id = $ezhand->mingxi_insert($info);
			if (!$mingxi_id) {
				echo '插入明细失败';
				exit;
			}
		}

		user_login($uid, $username);

		$goto = u('user', 'index');

		if (strpos($goto, 'http://') === false) {
			$goto = SITEURL . '/' . $goto;
		}
		if ($webset['ucenter']['open'] == 1 && $ucid > 0 && AJAX == 0) {
			echo $ucsynlogin = uc_user_synlogin($ucid); //同步登陆代码
		}

		jump($goto);
	} else {


    }
?>